<template>
  <view class="goods-item">
    <view class="goods_item_left">
      <radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler()"></radio>

      <!-- 左边盒子 -->
      <image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
    </view>
    <!-- 右边盒子 -->
    <view class="goods-item-right">
      <view class="goods-name">{{goods.goods_name}}</view>
      <view class="goods-info-box">
        <view class="goods-price">￥{{tofixed(goods.goods_price)}}</view>
        <uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my_goods",
    props: {
      goods: {
        type: Object,
        default: {}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
        // 默认图片地址
        defaultPic: 'https://ts1.cn.mm.bing.net/th/id/R-C.c187d181f69fdaeabe305ff7dc703817?rik=gb8yxqTJ5Xq5FQ&riu=http%3a%2f%2fpic.616pic.com%2fys_bnew_img%2f00%2f58%2f20%2f7iAcTfJhSA.jpg&ehk=DpREV5w4rqsBi5LE172coTqWDRIhtBwp0z1aDC69vLc%3d&risl=&pid=ImgRaw&r=0',
      };
    },
    methods: {
      tofixed(num) {
        return Number(num).toFixed(2)
      },
      radioClickHandler(){
        this.$emit('randio-change',{
          goods_id:this.goods.goods_id,
          goods_state:!this.goods.goods_state
        })
      },
      numChangeHandler(val){
        // console.log(val)
        this.$emit('num-change',{
          goods_id:this.goods.goods_id,
          goods_count:+val
        })
      }
    }
  }
</script>

<style lang="scss">
  .goods-item {
    width: 750rpx;
    box-sizing: border-box;
    background-color: white;
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid "#f0f0f0";

    .goods_item_left {
      display: flex;
      align-items: center;
      justify-content: space-between;
      

      .goods-pic {
        width: 100px;
        height: 100px;
        display: block;
      }

      margin-right: 5px;
    }

    .goods-item-right {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .goods-name {
        font-size: 13px;
      }

      .goods-info-box {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .goods-price {
          color: #C00000;
          font-weight: 16px;
        }
      }
    }
  }
</style>